# Create your models here.

from django.db import models

CONFIG_TIME_TYPE = (
    (0, "虚拟"),
    (1, '武器'),
    (2, '宝石'),
    (3, '卷轴'),
    (4, '材料'),
    (5, '宝箱'),
    (6, '坐骑'),
    (7, '坐骑装备'),
    (8, '宠物装备'),
    (9, '其他'),
)


# Create your models here.
# 在admin.py中配置显示的列
# 需要在项目目录下执行以下两个指令
# python manage.py makemigrations
# python manage.py migrage
class ConfigArea(models.Model):
    id = models.IntegerField(primary_key=True,db_column='id')
    name = models.CharField(max_length=200)
    description = models.CharField(max_length=200)


    class Meta:
        db_table = 'config_area'
        #同时可以多字段进行排序
        # ordering = ["-id"]  #order by desc
        ordering = ["id"]  #order by asc

    # def __unicode__(self):
    #     return self.name
    def __str__(self):
        return self.name

class ConfigAreaLevel(models.Model):
    id = models.IntegerField(primary_key=True,default=0)
    config_area = models.ForeignKey(to="ConfigArea",db_column="config_area_id")
    name = models.CharField(max_length=100)

    class Meta:
        db_table = 'config_area_level'

    def __str__(self):
        return self.name

class ConfigItem(models.Model):
    id = models.IntegerField(primary_key=True, default=0)
    type = models.IntegerField(choices=CONFIG_TIME_TYPE,default=1)
    name = models.CharField(max_length=200)
    description = models.CharField(max_length=200)

    class Meta:
        db_table = 'config_item'
        ordering = ["id"]

    # def __unicode__(self):
    #     return self.name
    def __str__(self):
        return self.name

class User(models.Model):
    id=models.IntegerField(primary_key=True,default=0)
    name=models.CharField(max_length=50,default='')
    email = models.EmailField(max_length=50)
    icon = models.ImageField(upload_to='img/%Y/%m/%d',db_column='icon_img')
    create_date = models.DateTimeField()

    class Meta:
        db_table='user'

    def __str__(self):
        return self.name

class UserDesc(models.Model):
    id = models.IntegerField(primary_key=True,default=0)
    user = models.OneToOneField(db_column='user_id',to='User')
    description = models.CharField(max_length=50,default='')

    class Meta:
        db_table = 'user_desc'

    def __str__(self):
        return str(self.id)